/*
 * [Ronny Abraham]
 * [ronnya@gmail.com]
 * CS530:DUI, Assignment [#1]
 */

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import javax.swing.BorderFactory;
import javax.swing.JPanel;

/*
 * PreviewPanel
 * A panel for the preview
 */

public class PreviewPanel extends JPanel
{
	public PreviewPanel(ActorGeometry geometry)
	{
		geom = geometry;
		geom.worldToPanel();
		itsShirtColor = ClothesColor.getColorVal(ClothesColor.blue);
		itsPantsColor = ClothesColor.getColorVal(ClothesColor.yellow);
		setBorder(BorderFactory.createLineBorder(Color.black));
	}
	
	public Dimension getPreferredSize() 
	{
        return new Dimension(ActorGeometry.panelDimension);
    }
	
	protected void paintComponent(Graphics g) 
	{
        super.paintComponent(g);
        
        Graphics2D g2d = (Graphics2D)g;
        if(visible == false)
        {
        	g2d.clearRect(0, 0, getPreferredSize().width, getPreferredSize().height);
        	return;
        }
        
        // draw head
        g2d.drawOval(geom.headPosition.x, geom.headPosition.y, geom.headWidth, geom.headHeight);
        // draw eyes
        g2d.drawOval(geom.eyeR.x, geom.eyeR.y, geom.eyeWidth, geom.eyeHeight);
        g2d.fillOval(geom.eyeR.x, geom.eyeR.y, geom.eyeWidth, geom.eyeHeight);
        g2d.drawOval(geom.eyeL.x, geom.eyeL.y, geom.eyeWidth, geom.eyeHeight);
        g2d.fillOval(geom.eyeL.x, geom.eyeL.y, geom.eyeWidth, geom.eyeHeight);
        // draw eye sockets
        g2d.drawOval(geom.socketR.x, geom.socketR.y, geom.socketWidth, geom.socketHeight);
        g2d.drawOval(geom.socketL.x, geom.socketL.y, geom.socketWidth, geom.socketHeight);
        // expression
        if(drawArc == true)
        {
        	g2d.drawArc(geom.mouthPos.x, geom.mouthPos.y, geom.mouthWidth, geom.mouthHeight, geom.startAngle, geom.arcAngle);
        }
        else
        {
        	g2d.drawLine(geom.mouthNeutralR.x, geom.mouthNeutralR.y, geom.mouthNeutralL.x, geom.mouthNeutralL.y);
        }
        // draw shirt
        g2d.setColor(itsShirtColor);
        g2d.fillPolygon(geom.shirt);
        g2d.setColor(Color.BLACK);
        g2d.drawPolygon(geom.shirt);
        //draw Pants
        g2d.setColor(itsPantsColor);
        g2d.fillPolygon(geom.pants);
        g2d.setColor(Color.BLACK);
        g2d.drawPolygon(geom.pants);
    }
	
	public static Point actorCenter = new Point(100, 150);
	public ActorGeometry geom;
	public Color itsShirtColor, itsPantsColor;
	public boolean drawArc = true;
	boolean visible = true;
}
